package com.demohomework.homeworkdemo.mapper;


import com.demohomework.homeworkdemo.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    //根据用户名查询用户信息
    @Select("select * from student where username = #{username}")
    Student findbyUsername(String username);

    //注册学生
    @Insert("INSERT INTO student (username, password) VALUES (#{username}, #{md5Password})")
    void add(String username, String md5Password);

    //更新信息
    @Update("update student set username = #{username}, email = #{email},name = #{name},phone = #{phone},college=#{college},year_of_study=#{yearOfStudy}, updated_at = now()" +
            " where id = #{id}")
    void update(Student student);

    //更新密码
    @Update("update student set password = #{md5Password} where id = #{id}")
    void updatePwd(String md5Password, Integer id);

    @Select("select * from student")
    List<Student> list();

    @Delete("delete from student where id = #{id}")
    void delete(Integer id);

    //添加学生
    @Insert("INSERT INTO student (username, password, email, name, phone,college,major, year_of_study, created_at, updated_at)" +
            " VALUES (#{username}, #{password}, #{email}, #{name}, #{phone},#{college},#{major},#{yearOfStudy}, now(), now())")
    void stuAdd(Student student);

    //根据id查询学生信息
    @Select("select * from student where id = #{id}")
    Student findId(Integer id);
}
